<?php

// Acceso restringido
defined('JL') or die('Acceso restringido');

class ImagesModel extends JLModelBase {

    /**
     * Funcion que retorna Images
     * @Retorna array
     */
    public function getImagesById($id) {
        $_true = null;

        $sql = "SELECT 
              `int_id_image`,
              `int_id_gallery`,
              `var_name_image`
            FROM 
              `tbl_images`  
            WHERE int_id_image = " . $this->DB->Quote($id) . "";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = $this->DB->getDataArray();
            $_true = $_true[0];
        }

        return $_true;
    }

    /**
     * Inserta Images
     * @Retorna int
     */
    public function insertImages($int_id_gallery, $var_name_image, $var_name_image_html) {
        $_true = 0;

        $sql = "INSERT INTO 
              `tbl_images`
            (
              `int_id_gallery`,
              `var_name_image`,
              var_name_image_html
            ) 
            VALUE(
              " . $this->DB->Quote($int_id_gallery) . ",
              " . $this->DB->Quote($var_name_image) . ",
              " . $this->DB->Quote($var_name_image_html) . "
            )";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = $this->DB->getInsertedId();
        }

        return $_true;
    }

    /**
     * Elimina Images
     * @Retorna bool
     */
    public function deleteImages($id) {
        $_true = false;

        $sql = "DELETE FROM 
              `tbl_images` 
            WHERE 
              `int_id_image` = " . $this->DB->Quote($id) . " ";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

    /**
     * Elimina Images segun galeria
     * @Retorna bool
     */
    public function deleteImagesByIdGallery($id) {
        $_true = false;

        $sql = "DELETE FROM 
              `tbl_images` 
            WHERE 
              `int_id_gallery` = " . $this->DB->Quote($id) . " ";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

}